;; -*- coding: utf-8 -*-
(eval-after-load 'dired
  '(progn
     (require 'dired+)
     (setq dired-recursive-deletes 'top)
     (setq dired-recursive-copies 'top)
     (setq directory-free-space-args "-Phk")
     (setq dired-auto-revert-buffer t)
     (setq dired-dwim-target t)
     (setq dired-listing-switches "-lhDGa")

     ;; dired-tar
     ;; 使用'T'来打包或者解压文件夹，需要gzip和unzip支持。
     (require 'dired-tar)

     ;; Dired单buffer
     (defadvice dired-find-file (around dired-find-file-single-buffer activate)
       "Replace current buffer if file is a directory."
       (interactive)
       (let ((orig (current-buffer))
	     (filename (dired-get-file-for-visit)))
	 ad-do-it
	 (when (and (file-directory-p filename)
		    (not (eq (current-buffer) orig)))
	   (kill-buffer orig))))

     (defadvice dired-up-directory (around dired-up-directory-single-buffer activate)
       "Replace current buffer if file is a directory."
       (interactive)
       (let ((orig (current-buffer)))
	 ad-do-it
	 (kill-buffer orig)))

     ;; 使用'E'打开ediff
     (define-key dired-mode-map (kbd "E") 'ediff-files)))

(provide 'init-dired)
